package com.wlts.wzy.sys_shiro.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wlts.wzy.Result.Result;
import com.wlts.wzy.sys_shiro.entity.SysPermission;
import com.wlts.wzy.sys_shiro.service.impl.SysPermissionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDateTime;

/**
 * <p>
 * 宅配商品类型表 前端控制器
 * </p>
 *
 * @author wuzhiyong
 * @since 2019-03-27
 */
@ApiIgnore
@RestController
@RequestMapping("/sys-permission")
public class SysPermissionController {
    @Autowired
    private SysPermissionServiceImpl sysPermissionService;
    /**
     * 角色权限创建
     * @param sysPermission
     * @return
     */
    @RequestMapping("buildsysPermission")
    public Result builesysPermission(@RequestBody SysPermission sysPermission){
        sysPermission.setCreateDate(LocalDateTime.now());
        sysPermission.setUpdateDate(LocalDateTime.now());
        SysPermission sysPermission1=sysPermissionService.getOne(new QueryWrapper<SysPermission>().eq("permissionname",sysPermission.getPermissionname()).eq("del_flag","0"));
        if(sysPermission1==null){
            sysPermissionService.save(sysPermission);
              return new Result<>();
        }
        return new Result<>("角色权限重复！");
    }
    //删除
    @RequestMapping("deletesysPermission")
    public Result deletesysPermission(@RequestBody SysPermission sysPermission) {
        sysPermission.setUpdateDate(LocalDateTime.now());
        SysPermission sysPermission1 = sysPermissionService.getById(sysPermission.getId());
        if (sysPermission1 != null) {
            sysPermission1.setDelFlag("1");
            sysPermissionService.updateById(sysPermission1);
              return new Result<>();
        }
        return new Result<>(500,"删除失败！");
    }
    //修改
    @RequestMapping("changesysPermission")
    public Result changesysPermission(@RequestBody SysPermission sysPermission) {
        sysPermission.setUpdateDate(LocalDateTime.now());
        SysPermission sysPermission1 = sysPermissionService.getById(sysPermission.getId());
        if (sysPermission1 != null) {
            sysPermissionService.updateById(sysPermission);
              return new Result<>();
        }
        return new Result<>(500,"修改失败！");
    }
    //查询
    @RequestMapping("selectsysPermission")
    public Result selectsysPermission(@RequestBody SysPermission sysPermission) {
        sysPermission.setUpdateDate(LocalDateTime.now());
        SysPermission sysPermission1 = sysPermissionService.getById(sysPermission.getId());
          return Result.buildResult(sysPermission1);
    }


}
